package co.yixiang.hw.repository;

import co.yixiang.hw.domain.YxStoreCart;
import co.yixiang.hw.vo.YxStoreCartListVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/**
* @author Walert
* @date 2020-02-13
*/
public interface YxStoreCartRepository extends JpaRepository<YxStoreCart, Long>, JpaSpecificationExecutor<YxStoreCart> {

    @Query(value = "select " +
            "   t.id, " +
            "   m1.image, " +
            "   m1.store_name   as storeName, " +
            "   m1.store_info   as storeInfo, " +
            "   m1.price, " +
            "   m1.ot_price     as otPrice, " +
            "   m1.unit_name    as unitName, " +
            "   t.add_time      as addTime, " +
            "   t.cart_num      as cartNum, " +
            "   t.product_id    as productId, " +
            "   t.is_check      as isCheck, " +
            "   t.uid " +
            "from yx_store_cart t  " +
            "left join yx_store_product m1 on (t.product_id = m1.id and m1.is_del = 0) " +
            "where t.uid = ?1 and t.is_del = 0 and m1.is_del = 0",
            countQuery = "select " +
                    "   count(1), " +
                    "from yx_store_cart t  " +
                    "left join yx_store_product m1 on (t.product_id = m1.id and m1.is_del = 0) " +
                    "where t.uid = ?1 and t.is_del = 0 and m1.is_del = 0",
            nativeQuery = true)
    List<Map> findUserCartList(Long uid);


}